package com.iot.service.mqtt.model.request;

import com.iot.service.mqtt.model.fix.TlMqttFixedHead;
import com.iot.service.mqtt.model.payload.TlMqttPublishPayload;
import com.iot.service.mqtt.model.variable.TlMqttPublishVariableHead;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttQoS;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @ClassName：TlMqttPublishReq
 * @Author: hszhou
 * @Date: 2024/11/26 13:23
 * @Description: 发布消息
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class TlMqttPublishReq   {


    private TlMqttFixedHead fixedHead;
    private TlMqttPublishVariableHead variableHead;
    private TlMqttPublishPayload payload;


    public static TlMqttPublishReq build(String topic,
                                            MqttQoS qoS,
                                            boolean retain,
                                            String content,
                                            Long messageId){
        TlMqttFixedHead fixedHead = TlMqttFixedHead.build(MqttMessageType.PUBLISH,qoS,retain);
        TlMqttPublishVariableHead variableHead = TlMqttPublishVariableHead.build(topic, messageId);
        TlMqttPublishPayload payload = TlMqttPublishPayload.build(content);
        return new TlMqttPublishReq(fixedHead,variableHead,payload);
    }


}
